package com.uaa.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author iszengziqiang@163.com
 * @date 2021-08-25 13:51
 * @Version: 1.0
 * @desc
 */
@Data
@NoArgsConstructor
public class ResultJson<T> {

    private String time;
    private boolean status;
    private int code;
    private String msg;
    private T data;

    public ResultJson(boolean status, int code, String msg, T data) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.time = LocalDateTime.now().toString();
    }

    public ResultJson(boolean status, int code, String msg) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        this.time = LocalDateTime.now().toString();
    }

    public static <T> ResultJson<T> succeed(ResultEnum resultEnum, T data) {
        return new ResultJson<>(true, resultEnum.code, resultEnum.msg, data);
    }

    public static <T> ResultJson<T> succeed(ResultEnum resultEnum) {
        return new ResultJson<>(true, resultEnum.code, resultEnum.msg);
    }

    public static <T> ResultJson<T> file(ResultEnum resultEnum) {
        return new ResultJson<>(false, resultEnum.code, resultEnum.msg);
    }

    public static <T> ResultJson<T> file(ResultEnum resultEnum, T data) {
        return new ResultJson<>(false, resultEnum.code, resultEnum.msg, data);
    }

}
